// 1、引入axios
import axios from "axios";
// 2、引入elementui的loading
import { Loading } from 'element-ui';
// import { config } from "vue/types/umd";
// let loadingInstance = Loading.service(options);
// 3、添加axios的默认属性，请求超时时间
axios.default.timeout = 5000
let loadingInstance = null
// 4、设置基础地址
// axios.defaults.baseURL = "http://127.0.0.1:8888/api/private/v1/"
axios.defaults.baseURL = "/api"
// 6、获取token
let token = localStorage.getItem('token')
console.log('token', token);

// 5、axios拦截器
// 1) 请求拦截器
axios.interceptors.request.use((config) => {
    console.log(config)
    // 设置请求头
    config.headers["Authorization"] = token

    loadingInstance = Loading.service({
        text: "Loading",
        spinner: "el-icon-loading",
    });



    return config
})

// 2)响应拦截
axios.interceptors.response.use(res => {
    console.log(res);
    loadingInstance.close()
    return res
})

// 抛出axios
export default axios